<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets">


<body>
<ui:composition template="/template2.xhtml">
	<ui:define name="titulo">Listar Veiculo</ui:define>
	<ui:define name="barra_titulo">Listar Veiculo</ui:define>
	<ui:define name="corpo">
			
			<p:messages>
			</p:messages>
	
			<h:form id="formListar">
				<p:dataTable var="veiculo"
					value="#{veiculoBean.veiculos}" selection="#{veiculoBean.veiculo }" update="display" selectionMode="single" emptyMessage="Motoristas não Cadastrados" rowKey="#{veiculo.modelo}">
					 
					 <p:ajax event="rowSelect"   
                   		 update=":formAlterar:infoAlt" oncomplete="dialogo.show()" />
					
					<p:column>
						<f:facet name="header">
							<h:outputText value="Modelo:" />
						</f:facet>
						<h:outputText value="#{veiculo.modelo}" />
					</p:column>
					<p:column>
						<f:facet name="header">
							<h:outputText value="Placa:" />
						</f:facet>
						<h:outputText value="#{veiculo.placa}" />
					</p:column>
					
					<p:column>
						<f:facet name="header">
							<h:outputText value="Porta:" />
						</f:facet>
						<h:outputText value="#{veiculo.porta}" />
					</p:column>
					<p:column>
						<f:facet name="header">
							<h:outputText value="Titular:" />
						</f:facet>
						<h:outputText value="#{veiculo.titular}" />
					</p:column>
					<p:column>
						<p:commandLink type="button" oncomplete="cd.show()" update=":dlg">
							<h:graphicImage alt="Excluir Registro" library="imagens" name="delete.png"
								styleClass="image"></h:graphicImage>
							<f:setPropertyActionListener target="#{veiculoBean.veiculo}"
								value="#{veiculo}" />
						</p:commandLink>
					</p:column>
				</p:dataTable>
			</h:form>
				
				<h:form id="dlg">
					<p:confirmDialog message="Deseja realmente excluir o veiculo: #{veiculoBean.veiculo.placa}?"
						hideEffect="explode" header="Excluir" severity="alert" widgetVar="cd">
						<p:commandButton value="Sim" actionListener="#{veiculoBean.excluir}"
							update=":formListar" oncomplete="cd.hide()" />
						<p:commandButton value="Não" onclick="cd.hide()" type="button" />
					</p:confirmDialog>
				</h:form>

			<p:dialog header="Editar Veiculo" widgetVar="dialogo" width="400"
				modal="true" resizable="false" closable="false">
				<p:outputPanel id="display">
					<h:form id="formAlterar">
						<h:panelGrid columns="2" id="infoAlt">
							<h:outputLabel value="Modelo:" />
							<p:inputText value="#{veiculoBean.veiculo.modelo}" />
							<h:outputLabel value="Placa:" />
							<p:inputMask value="#{veiculoBean.veiculo.placa}" mask="aaa-9999" />
							<h:outputLabel value="Porta:" />
							<p:inputText size="2" value="#{veiculoBean.veiculo.porta}" />
							<h:outputLabel value="Titular:" />
							<p:inputText value="#{veiculoBean.veiculo.titular}" />
						</h:panelGrid>
						<br />
						<p:commandButton action="#{veiculoBean.editar}" value="Salvar"
							update=":formListar" oncomplete="dialogo.hide()" />
						<p:commandButton value="Cancelar"
							action="#{veiculoBean.cancelaEditar}" oncomplete="dialogo.hide()" />
					</h:form>
				</p:outputPanel>
			</p:dialog>

		</ui:define>
		</ui:composition>		
</body>
</html>
